package com.eboss2.sbs.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ProgressBar;

import com.eboss2.sbs.R;
import com.eboss2.sbs.util.ImageLoader;

import java.util.ArrayList;
import java.util.List;



/**
 * 主页面中GridView的适配器
 * 
 * @author hanj
 */

public class AdapterShopSaleComplete extends BaseAdapter {

    private Context context;
    private List<String> imagePathList = new ArrayList<String>();
    private ImageLoader mImageLoader;

    public AdapterShopSaleComplete(Context context, List<String> imagePathList) {
        this.context = context;
        this.imagePathList = imagePathList;
        mImageLoader = ImageLoader.getInstance(3, ImageLoader.Type.LIFO);
    }

    @Override
    public int getCount() {
        return imagePathList == null ? 0 : imagePathList.size();
    }

    @Override
    public Object getItem(int position) {
        return imagePathList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_life_iv, null);

            holder.imageView = (ImageView) convertView.findViewById(R.id.main_gridView_item_photo);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        String url = imagePathList.get(position);
       
        mImageLoader.loadImage(url, holder.imageView, true);
        return convertView;
    }

    private class ViewHolder {

        ImageView imageView;
        ImageView iv_status;
        ProgressBar progressbar;
    }

}
